package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	file, err := os.OpenFile("./3.txt", os.O_RDWR|os.O_CREATE, 0666)
	if err != nil {
		fmt.Println(err)
	}
	reader := bufio.NewReader(file)
	lineIndex := 1
	for {
		line, errRead := reader.ReadString('\n')
		if errRead == io.EOF {
			fmt.Println(lineIndex)
			break
		}
		fmt.Print(line)
		lineIndex++
	}
	str := "xxx "
	writer := bufio.NewWriter(file)
	var str1 string
	for i := 0; i < 5; i++ {
		str1 = str + strconv.FormatInt(int64(i)+1, 10)
		writer.WriteString(str1)
		writer.WriteString("\r\n")
	}
	writer.Flush()
	file.Close()
}
